package cn.ithers.blog.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: zhanghuan
 * @date: 2020/10/20 13:24
 * @description: 自定义工具类
 */
public class CustomUtils {

    /**
     * 获取  http://localhost:8080
     *
     * @param request
     * @return
     */
    public static String getDomain(HttpServletRequest request) {

        StringBuffer requestURI = request.getRequestURL();
        String servletPath = request.getServletPath();
        // requestURI--------->http://localhost:8080/portal/image/qr_code/768088956859318272
        //servletPath-------->/portal/image/qr_code/768088956859318272
        //requestURI.toString().replace(servletPath, "")  ->http://localhost:8080
        return requestURI.toString().replace(servletPath, "");
    }

}
